package com.feicheng.lanniao.controller;

import java.time.LocalDateTime;

import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.feicheng.lanniao.entity.House;
import com.feicheng.lanniao.exception.SystemException;
import com.feicheng.lanniao.result.ResultInfo;
import com.feicheng.lanniao.service.IHouseService;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author feichengTech
 * @since 2021-09-02
 */
@RestController
@RequestMapping("/lanniao-admin/house")
public class HouseController {

	@Autowired
	private IHouseService iHouseService;

	/**
	 * 分页查询
	 * @param des            描述
	 * @param provienceId    区
	 * @param cityId         市
	 * @param reignId        区
	 * @param currentPage    当前页
	 * @param pageSize       每页多少条
	 * @return 房子列表集合
	 */
	@GetMapping("/page")
	public ResultInfo getHouseList(
			String des, 
			Integer provienceId, Integer cityId, Integer reignId, 
			@RequestParam(defaultValue = "1") Integer currentPage,
			@RequestParam(defaultValue = "10") Integer pageSize) {
		return iHouseService.getHousePage(
				des,provienceId, cityId, reignId,
				currentPage, pageSize);
	}
	/**
	 * 修改方法(假删除)
	 * @param house 房子对象
	 * @return 返回布尔结果 成功-true 失败-false
	 */
	@DeleteMapping("/info")
	public ResultInfo deleteHouse(House house) {
		if (null == house.getHouseId()) {
			throw new SystemException("房子id为空");
		}
		return iHouseService.deleteHouse(house);
	}
	/**
	 * 详情页的修改方法
	 * @param house 房子对象
	 * @return 返回布尔结果 成功-true 失败-false
	 */
	@PutMapping("/info")
	public ResultInfo updateCourseInfo(House house) {
		return iHouseService.updateHouse(house);
	}
	/**
	 * 详情页查询
	 * @param houseId 房子id
	 * @return 返回1个ResultInfo对象
	 */
	@GetMapping("/info")
	public ResultInfo findDetails(Integer houseId) {
		return iHouseService.findDetails(houseId);
	}
	/**
	 * 增加方法
	 * @param house 房子对象
	 * @return 返回布尔结果 成功-true 失败-false
	 */
	@PostMapping("/info")
	public ResultInfo addHouse(House house) {
		return iHouseService.addHouse(house);
	}

}
